# GitHub Actions workflow file.
#
# For more information, visit
# https://docs.github.com/actions/learn-github-actions.

---
name: release

# Makes workflow run on Git tag.
on:
  push:
    tags:
      - "**"
  workflow_dispatch:
    inputs:
      debug:
        default: false
        description: Use Tmate session for debugging
        type: boolean

env:
  PIP_DISABLE_PIP_VERSION_CHECK: "true"
  PIP_ROOT_USER_ACTION: ignore
  POETRY_VIRTUALENVS_IN_PROJECT: "true"
  PYTHON_KEYRING_BACKEND: "keyring.backends.null.Keyring"

jobs:
  release:
    name: Make GitHub release and publish Python package
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code repository
        uses: actions/checkout@v4
      - name: Install Python interpreter
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Install Python packages
        run: |
          python --version
          python -m pip --version
          python -m pip install poetry
          poetry install --no-dev
      - name: Build Python package
        run: poetry build
      - name: Create GitHub release
        uses: softprops/action-gh-release@v1
        with:
          body: >-
            See the [changelog](https://notabug.org/c0digam0s/sharpen/blob/${{
            github.ref_name }}/CHANGELOG.md) for more information.
          files: |
            dist/sharpen-${{ github.ref_name }}-py3-none-any.whl
            dist/sharpen-${{ github.ref_name }}.tar.gz
          name: sharpen ${{ github.ref_name }}
          tag_name: ${{ github.ref }}
      - name: Setup Tmate session if debug enabled
        if: >-
          ${{ always() && github.event_name == 'workflow_dispatch' &&
          inputs.debug }}
        timeout-minutes: 60
        uses: mxschmitt/action-tmate@v3
